import msg from "../../../utils/msg";
import { activity_list, getFollowClub, getGameList, subscribe } from "../../../utils/request/api"
import User from "../../../utils/user";
import {filePath1} from "../../../utils/request/route";
import Notify from '../../../miniprogram_npm/@vant/weapp/notify/notify';
// pages/user/myFollow/myFollow.ts
Page({

  /**
   * 页面的初始数据
   */
  data: {
    game:[],
    act:[],
    mer:'',
    filePath1,
  },
  goToDetail3:async function(e:any){
    let index = e.currentTarget.dataset.index;
    let data:any = this.data.mer[index];
    //选择
    let choice:any = await msg.ActionSheet(['查看它发布的赛事','查看它发布的活动','取消关注'],'请选择');
    let tapIndex = choice.tapIndex;
    let user= new User;
    switch(tapIndex){
      case 0:
        wx.navigateTo({
          url:'/pages/user/myCom/myCom'+'?club_id='+data.club_id,
        });break;
      case 1:
        wx.navigateTo({
          url:'/pages/user/myActiv/myActiv'+'?club_id='+data.club_id,
        });break;
      case 2:
        msg.Loading();
        let res:any = await subscribe({GF_ID:user.GF_ID,type:1,control:0,id:data.club_id});
        if(res.data.error==0){
          Notify({ type: 'success', message: '取关成功,刷新显示' })
        }
        else Notify({ type: 'warning', message: '取关失败,'+res.data.msg });
        msg.hideLoading();
        break;
        
    }
    
  },
  goToDetail(e:any){
    let index = e.currentTarget.dataset.index;
    let data:any = this.data.game[index];
    wx.navigateTo({
      url:"/pages/compete/comDetail/comDetail"+'?id='+data.id,
    });
  },
  goToDetail2(e:any){
    let index = e.currentTarget.dataset.index;
    let data:any = this.data.act[index];
    wx.navigateTo({
      url:"/pages/act/actDetail/actDetail"+'?id='+data.id,
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad:async function() {
    msg.Loading();
    let user = new User;
    let game:any = await getGameList({type:3,visit_gfid:user.GF_ID});
    //console.log('game=',game);
    let act:any = await activity_list({type:3,GF_ID:user.GF_ID});
    //console.log('act=',act);
    let mer:any = await getFollowClub({GF_ID:user.GF_ID});
    this.setData({
      game:game.data.datas,
      act:act.data.datas,
      mer:mer.data.datas,
    });
    msg.hideLoading();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})